home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Internet Tools (InfoMagic)
/
Internet Tools.iso
/
news
/
moderating
/
multimod.shar.Z
/
multimod.shar
/
multimod.c
next >
Wrap
C/C++ Source or Header
|
1994-07-21
|
3KB
|
119 lines
/* This program is designed to implement multiple moderators. It is designed
* to be called by sendmail when mail is sent to a moderated group alias, with
* the name of a file containing up to 20 moderator addresses as argument, and
* randomly send the message to one of the moderator addresses
*
*
* Usage:
*
* multimod [-a] [-c cc-address] file-of-moderators
*
* The message should be on the standard input. This is designed to be
* mailed to via an alias, e.g. for sendmail's /usr/lib/aliases:
*
* feminism: "|/usr/local/bin/multimod /usr/local/lib/feminism.moderators"
*
* Arguments:
*
* Other than flags, only one: the name of a file containing moderator
* addresses, one per line.
*
* Flags:
*
* -a: send to all the moderators in the file. This is useful if you want
* to have an alias that will reach all the moderators
*
* -c: indicates that the next argument is an address to which a copy
* of the article should be sent. This is useful if you want to
* archive all the articles submitted.
*/
#include <stdio.h>
FILE *mod; /* moderators file */
#define SHIFT (++argv,--argc)
#define MAXMOD 20
#define POSTMASTER "postmaster@ncar.ucar.edu"
main(argc,argv) char **argv; int argc; {
char *addr[MAXMOD]; /* array of moderator addresses */
char line[1024]; /* buffer for reading in moderator addresses */
char *cc=NULL; /* cc: address */
register int i;
int all=0; /* send to all moderators */
void error();
char *malloc();
void send_mail_to();
while(SHIFT && **argv == '-') { /* process flags */
if (strlen(*argv) != 2) {
sprintf(line,"Unknown option: %s\n",*argv);
error(line);
}
switch(*(*argv+1)) {
case 'a': /* send to all moderators */
if (cc != NULL) error("May not use both -a and -c\n");
all++;
break;
case 'c': /* send copy to designated next argument address */
if (! SHIFT) error("-c option requires value\n");
if (all) error("May not use both -a and -c\n");
cc= *argv;
break;
default:
sprintf(line,"Unknown flag: %s\n",*argv);
error(line);
}
}
if (argc != 1) error("Usage: multimod [-a] [-c copyto] moderator-file\n");
if ((mod=fopen(*argv,"r")) == NULL) {
sprintf(line,"Cannot open %s\n",*argv);
error(line);
}
for (i=0; i < MAXMOD; i++) {
if (fgets(line,1024,mod) == NULL) break;
if (line[0] == '#') { --i; continue; }
if (line[strlen(line)-1] == '\n') line[strlen(line)-1]=0; /* strip newline */
if ((addr[i]=malloc(strlen(line))) == NULL) error("Out of memory\n");
strcpy(addr[i],line);
}
if (i >= MAXMOD) error("Too many moderators\n");
if (all) {
register int j;
for(line[0]=0,j=0; j < i; j++) {
strcat(line,addr[j]);
strcat(line," ");
}
printf("%s\n",line);
send_mail_to(line);
} else {
i=time(NULL)%i;
printf("%s\n",addr[i]);
strcpy(line,addr[i]);
if (cc != NULL) {
strcat(line," ");
strcat(line,cc);
}
send_mail_to(line);
}
exit(0);
}
void
error(msg) char *msg; { /* print error message and exit */
void send_mail_to();
fputs(msg,stdout);
send_mail_to(POSTMASTER);
exit(1);
}
void
send_mail_to(s) char *s; { /*exec sendmail and deliver to designated address */
execl("/usr/lib/sendmail","sendmail",s,0);
perror("multimod: /usr/lib/sendmail");
exit(1);
}